﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using ORM.Common.DataAnnotations;
using ORM.Resources;

namespace ORM.Business.Models.Entities
{
    public class Question
    {
        #region Primitive properties

        public int Id { get; set; }

        [Required(ErrorMessageResourceType = typeof(ValidationMessages),
                  ErrorMessageResourceName = "QuestionTitleRequired")]
        [StringLengthExtended(100, MinimumLength = 10)]
        [Display(Name = "Question_Title", ResourceType = typeof(Labels))]
        public string Title { get; set; }

        public string TitleUrl { get; set; }

        [Required(ErrorMessageResourceType = typeof(ValidationMessages),
                  ErrorMessageResourceName = "QuestionDescriptionRequired")]
        [Display(Name = "Question_Description", ResourceType = typeof(Labels))]
        //[StringLengthExtended(int.MaxValue / 2)] // Don't remove this line otherwise EF will throw a validation exception
        [AllowHtml]
        public string ContentHtml { get; set; }

        public int UpVotes { get; set; }
        public int DownVotes { get; set; }
        public int Views { get; set; }

        public int Answers { get; set; }
        public int Reports { get; set; }

        public int PostedById { get; set; }

        public DateTime PostedDate { get; set; }


        public int? UpdatedById { get; set; }

        public DateTime? LastUpdate { get; set; }
        public bool IsDeleted { get; set; }
        public bool IsResolved { get; set; }
        [Required(ErrorMessageResourceType = typeof(ValidationMessages),
                  ErrorMessageResourceName = "ModelIdRequired")]
        public int ModelId { get; set; }
        
        public int Point { get; set; }
        [NotMapped]
        public virtual bool IsVotedByCurrentUser { get; set; }
        [NotMapped]
        public virtual bool IsReportedByCurrentUser { get; set; }
        [NotMapped]
        public virtual bool IsAddedBookmarkByCurrentUser { get; set; }
        #endregion

        #region Navigation properties
        //public virtual ModelWithAllInformation ModelWithAllInfo { get; set; }
        [ForeignKey("PostedById")]
        public virtual user PostedBy { get; set; }

        [ForeignKey("UpdatedById")]
        public virtual user UpdatedBy { get; set; }

        [ForeignKey("ModelId")]
        public virtual Model Model { get; set; }

        //todo - HoaVT - uncomment later
        //public virtual ICollection<ReportedQuestion> ReportedQuestions { get; set; }

        //[InverseProperty("Question")]
        //public virtual ICollection<Answer> Answers { get; set; }

        #endregion
    }
}
